package com.wp.controller;

import com.wp.domain.UserInfo;
import com.wp.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author 卫鹏
 * @Description
 * @createTime 2021年11月05日 17:19:00
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;


   /* @RequestMapping("/login")
    public String login(@RequestParam(name = "username", required = false) String username,
                        @RequestParam(name = "password", required = false) String password,
                        Model model,
                        HttpServletResponse response,
                        HttpServletRequest request) throws ServletException, IOException {
        User user = userService.findByUsernameAndPassword(username, password);
        if (user == null) {
            return "500";
        }
        return "redirect:/pages/main.jsp";
    }*/

    @RequestMapping(value = "/register", method = RequestMethod.POST)
    public ModelAndView register(UserInfo user) {
        ModelAndView mv = new ModelAndView();
        userService.register(user);
        mv.addObject("username", user.getUserAccount());
        mv.setViewName("success");
        return mv;
    }


}
